package org.zjut.pso;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.zjut.bean.Resource;
import org.zjut.db.LearnConceptDataBase;
import org.zjut.db.LearnerCourseAttrDataBase;
import org.zjut.db.LearnerKnowledgeAttrDataBase;
import org.zjut.db.ResourceDataBase;
import org.zjut.util.CommonUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Rising
 * @date 2017/9/23
 * @des  算法1
 */
public class PSOone implements IPSO {

    LearnConceptDataBase mLearnConceptDataBase;
    ResourceDataBase mResourceDataBase;

    public PSOone(LearnConceptDataBase learnConceptDataBase, ResourceDataBase resourceDataBase) {
        this.mLearnConceptDataBase = learnConceptDataBase;
        this.mResourceDataBase = resourceDataBase;
    }

    /**
     * 算法核心
     * 这里仅返回某课程下的所有知识点
     * @param params
     * @return
     */
    @Override
    public List<Map<String, Object>> getRecommondKnowledge(Map<String, Object> params) {
        System.out.println("into getRecommondknowledge method:");
        try {
            //仅返回某课程下的知识点
            String courseCode = params.get("courseCode").toString();
            Map<String,Object> newParams = new HashMap<>();
            newParams.put("courseCode",courseCode);
            Map<String,Object> result = mLearnConceptDataBase.getLeanConcept(newParams);
            if(Boolean.valueOf(result.get("success").toString())){
                return (List<Map<String, Object>>) ((Map<String,Object>)result.get("message")).get("conceptInfo");
            }else{
                return null;
            }
        }catch (Exception e){
            System.out.println("getRecommondKnowledge---"+e.getMessage());
            return null;
        }
    }

    @Override
    public List<Map<String, Object>> sortReccomondKnowledge(List<Map<String, Object>> source) {
        return null;
    }

    @Override
    public List<Map<String, Object>> getRecommondResource(Map<String, Object> params) {
        try {
            Map<String,Object> result = mResourceDataBase.getResource(params);
            if(Boolean.valueOf(result.get("success").toString())){
                return (List<Map<String, Object>>) ((Map<String,Object>)result.get("message")).get("resourceInfos");
            }else{
                return null;
            }
        }catch (Exception e){
            System.out.println("getRecommondResource:"+e.getMessage());
            return null;
        }
    }

    @Override
    public List<Map<String, Object>> sortRecommondResource(Map<String, Object> params) {
        return null;
    }
}
